package com.golxen.framework.common.server.game.cmd.user;

import com.golxen.framework.ClientProtocol;
import com.golxen.framework.GameProtocol;
import com.golxen.framework.PBPacket.PBPacket;
import com.golxen.framework.common.server.agent.AgentPlayer;
import com.golxen.framework.common.server.game.cmd.AbstractCommand;
import com.golxen.framework.common.server.game.cmd.Cmd;
import com.golxen.framework.user.UserMgr;
import com.golxen.framework.user.player.GamePlayer;
import com.golxen.framework.user.player.PlayerState;
import com.golxen.protojava.LoginProto;
import com.golxen.utils.TimeUtils;
import com.google.protobuf.Message;
import io.netty.channel.ChannelConfig;


@Cmd(code = GameProtocol.S_PLAYER_PING, desc = "客户端心跳")
public class PingCmd extends AbstractCommand {

    @Override
    public Message parseData(PBPacket packet) throws Exception {
        return null;
    }

    @Override
    public void execute(GamePlayer player, PBPacket packet) throws Exception {
        int nowTime = (int) (System.currentTimeMillis() / 1000);
        LoginProto.PingDataMsg.Builder pingMsg = LoginProto.PingDataMsg.newBuilder();
        pingMsg.setTime(nowTime);
        pingMsg.setTimeZone(TimeUtils.getDefaultTimeZone());
        if (player != null) {

            player.setLastPingTime(System.currentTimeMillis());
            player.setState(PlayerState.ONLINE);
            player.sendPacket(ClientProtocol.U_PLAYER_PING, pingMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }

}
